#include "siteRequestUtil.h"
#include "log/Logging.h"
#include "common/httpUtil.h"

bool siteRequestUtil::access_service_query_get_localSite(string siteIp, qlibc::QData &response)
{
    qlibc::QData siteRequest;
    siteRequest.setString("service_id", "site_localSite");
    siteRequest.putData("request", qlibc::QData());
    LOG_GREEN << "get localSites from query: " << siteRequest.toJsonString();
    bool httpResRet = httpUtil::sitePostRequest(siteIp, 9000, siteRequest, response);
    if(!httpResRet || response.getInt("code") != 0){
        LOG_RED << "get local sites from query failed.....";
        return false;
    }
    return true;
}


bool siteRequestUtil::access_service_config_get_self_info(string siteIp, qlibc::QData &response)
{
    qlibc::QData request;
    request.setString("service_id", "get_self_info");
    request.putData("request", qlibc::QData());
    LOG_GREEN << "get paneConfig from config: " << request.toJsonString();
    bool httpResRet = httpUtil::sitePostRequest(siteIp, 9006, request, response);
    if(!httpResRet || response.getInt("code") != 0){
        LOG_RED << "get panelConfig from config failed.....";
        return false;
    }
    return true;
}

bool siteRequestUtil::access_service_master_get_all(string siteIp, qlibc::QData &response)
{
    qlibc::QData request;
    request.setString("service_id", "get_all");
    request.putData("request", qlibc::QData());
    LOG_GREEN << "get_all request: " << request.toJsonString();
    bool httpResRet = httpUtil::sitePostRequest(siteIp, 9012, request, response);
    if(!httpResRet || response.getInt("code") != 0){
        LOG_RED << "accesss master get all failed ...";
        return false;
    }
    return true;
}

bool siteRequestUtil::access_service_master_get_app_site_list(string siteIp, qlibc::QData &response)
{
    qlibc::QData request;
    request.setString("service_id", "get_app_site_list");
    request.putData("request", qlibc::QData());
    LOG_GREEN << "get_app_site_list request: " << request.toJsonString();
    bool httpResRet = httpUtil::sitePostRequest(siteIp, 9012, request, response);
    if(!httpResRet || response.getInt("code") != 0){
        LOG_RED << "accesss master get_app_site_list failed ...";
        return false;
    }
    return true;
}
